﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EnheimGallery.DAL.AccountManagementDAL
{
    public class NewUserData
    {
        public DateTime CreateDate;
        public string FullName;
    }
    public static class AccountManagementDAL
    {
         public static Guid UserId(string userName)
        {
             EnheimGalleryEntities db = new EnheimGalleryEntities();
             var createdUser = from user in db.aspnet_Users
                               where user.UserName == userName
                               select user.UserId;
             return createdUser.First();

        }
        public static void CompleteUserRegistration(string firstName,string surname,string userName)
        {
            EnheimGalleryEntities db = new EnheimGalleryEntities();

           Guid userId=UserId(userName);
            User newUser = new User()
            {
                FirstName = firstName,
                Surname = surname,
                UserId = userId,
                LastActionId=1
            };
            db.AddToUsers(newUser);
            db.SaveChanges();
          
        }

        public static List<string> ReadUserNames()
        {
            EnheimGalleryEntities db = new EnheimGalleryEntities();
            var userNames = from user in db.aspnet_Users
                            select user.UserName;

            List<string> returnList = userNames.ToList();

            return returnList;
        }
        public static List<NewUserData> NewUsersMessageInfo()
        {
            EnheimGalleryEntities db = new EnheimGalleryEntities();
            var newUsersQuery = from user in db.Users
                                from userasp in db.aspnet_Membership
                                where user.UserId == userasp.UserId
                                select new NewUserData { CreateDate = userasp.CreateDate, FullName = user.FirstName + " " + user.Surname };

            List<NewUserData> newUsersData = newUsersQuery.ToList();
            return newUsersData;
        }

        
    }
}
